<html>
<head><meta charset="utf-8"><title>built-in macros vs proc macro · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html">built-in macros vs proc macro</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="245236444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245236444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245236444">(Jul 07 2021 at 20:16)</a>:</h4>
<p>Is there any particular reason that some built-in macros are actually built-in rather than "regular" procedural macros? It seems like a number of macros (including all derives, <code>concat</code>, <code>concat_idents</code>, and probably more) could be done as a proc macro. Admittedly the current proc macro API is a bit limited in knowledge, but wouldn't that be a good opportunity to hammer out a more thorough API based on real-world usage? Something like <code>concat</code> or <code>concat_idents</code> could likely be implemented trivially, even with the current limited API.</p>



<a name="245236714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245236714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245236714">(Jul 07 2021 at 20:19)</a>:</h4>
<p>Historical artifact for sure, but also the proc macro implementation is definitely not zero cost (and I'm not sure it can be, but that's a harder claim). So there may be some benefits to in-tree impls there too. Generally I don't think there's too much point trying to extract them...</p>



<a name="245236949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245236949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245236949">(Jul 07 2021 at 20:21)</a>:</h4>
<p>I figured it was at least partially historical. What extra costs would there be? Re-building the partial AST after the macro is expanded?</p>



<a name="245238485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245238485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245238485">(Jul 07 2021 at 20:34)</a>:</h4>
<p>I am curious to know whether's there's an observable cost and what it might be... not that my own curiosity alone justifies that much work :P</p>



<a name="245238828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245238828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245238828">(Jul 07 2021 at 20:37)</a>:</h4>
<p>For sure. I likely wouldn't end up doing this myself, was just curious ¯\_(ツ)_/¯</p>



<a name="245239759"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245239759" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245239759">(Jul 07 2021 at 20:46)</a>:</h4>
<p>The implementation has to currently pass over C FFI, essentially serializing to bytes and then deserializing. That obviously is higher cost than function calls</p>



<a name="245240450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245240450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245240450">(Jul 07 2021 at 20:52)</a>:</h4>
<p>Right. Not thinking about the bridge. Hopefully that won't be necessary in the future. Some day™</p>



<a name="245244222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245244222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245244222">(Jul 07 2021 at 21:24)</a>:</h4>
<p>Also builtin macros directly construct the AST instead of a tokenstream that is then parsed.</p>



<a name="245244624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245244624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245244624">(Jul 07 2021 at 21:28)</a>:</h4>
<p>May I ask why the C FFI is necessary?</p>



<a name="245244950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245244950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245244950">(Jul 07 2021 at 21:30)</a>:</h4>
<p>So that proc macros can be built with a different rustc version than the one used to compile the host rustc they are loaded in. Happens during bootstrapping. Only the source code needs to match between the proc-macro and the host rustc because it uses the C abi.</p>



<a name="245245142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245245142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245245142">(Jul 07 2021 at 21:31)</a>:</h4>
<p>I see. Thanks!</p>



<a name="245247768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245247768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245247768">(Jul 07 2021 at 21:57)</a>:</h4>
<p>Also, we have some special cases for the built-in macros, and we'd have to make sure we can preserve those with proc macros.</p>



<a name="245247786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245247786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245247786">(Jul 07 2021 at 21:57)</a>:</h4>
<p>For instance, some macros that require string literals also accept <code>concat!</code> of string literals.</p>



<a name="245247793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245247793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245247793">(Jul 07 2021 at 21:57)</a>:</h4>
<p>We'd have to make sure we can still do that if we use a proc macro.</p>



<a name="245247804"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245247804" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245247804">(Jul 07 2021 at 21:57)</a>:</h4>
<p>Depending on the architecture, it might get <em>easier</em>...</p>



<a name="245248255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245248255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245248255">(Jul 07 2021 at 22:01)</a>:</h4>
<p>It's unfortunate hat the eager expansion RFC needed to be postponed...</p>



<a name="245453893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245453893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245453893">(Jul 09 2021 at 14:57)</a>:</h4>
<p>Heh, the experiments I did in <a href="https://docs.rs/with_builtin_macros">https://docs.rs/with_builtin_macros</a> may seem relevant.</p>
<p>But yeah, most built-in macros take advantage of being able to perform eager expansion of the "string literal expression", thus accepting stuff such as <code>format!(concat!(include_str!(env!("…")), "…"), …)</code>.</p>
<p>For instance, just look at the API hoops (callback style) <code>with_builtin_macros</code> needs to go through to "be eagerly expandable"</p>



<a name="245454074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245454074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245454074">(Jul 09 2021 at 14:58)</a>:</h4>
<p>(I'm still in love with the example showcased in <a href="https://docs.rs/with_builtin_macros/0.0.3/with_builtin_macros/builtin_macros/include_from_root/index.html">https://docs.rs/with_builtin_macros/0.0.3/with_builtin_macros/builtin_macros/include_from_root/index.html</a> <span aria-label="big smile" class="emoji emoji-1f604" role="img" title="big smile">:big_smile:</span> )</p>



<a name="245454124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245454124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245454124">(Jul 09 2021 at 14:59)</a>:</h4>
<p>one of the problems is that <code>proc_macro</code> depends on <code>std</code>, which depends on <code>alloc</code> and eventually <code>core</code></p>



<a name="245454164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245454164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245454164">(Jul 09 2021 at 14:59)</a>:</h4>
<p>but <code>core</code> has access to builtin macros. AFAIK it's impossible to square that circular dependency graph</p>



<a name="245454345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245454345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245454345">(Jul 09 2021 at 15:01)</a>:</h4>
<p>you can use a different copy of <code>std</code>+<code>proc_macro</code> to build a proc macro that <code>core</code> depends on at some point in the bootstrap (the very first <code>core</code> being locally built during a Rust build, I believe), but not other points</p>



<a name="245454380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245454380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245454380">(Jul 09 2021 at 15:01)</a>:</h4>
<p>similarly, <code>-Z build-std</code> <em>might</em> be able to make it work, but I can't guarantee it</p>



<a name="245454802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245454802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245454802">(Jul 09 2021 at 15:04)</a>:</h4>
<p>there's certainly <em>build scripts</em> that run during the build of <code>std</code> (for backtrace support maybe?), but proc macros have to be compatible with the <code>rustc</code> that will execute them, so we'd have to have version-to-version binary compatibility (maybe version the proc macro bridge, but only support 2 versions at once? and one of them is mostly just a redirect to the other one)</p>



<a name="245454885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245454885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245454885">(Jul 09 2021 at 15:05)</a>:</h4>
<p>welp now I actually have an idea of how to do this (which I've considered implausible/impractical) for so long :P</p>



<a name="245454917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245454917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245454917">(Jul 09 2021 at 15:05)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="270901">@Nika Layzell</span> (given her recent PRs, and related discussions we've had)</p>



<a name="245455909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245455909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nika Layzell <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245455909">(Jul 09 2021 at 15:13)</a>:</h4>
<p>It'd definitely be possible to version the proc macro bridge and support 2 rolling versions in rustc if that's a thing we wanted to do, though we'd need to be a bit careful about it in that case to make sure that each side of the connection isn't making too many assumptions, and would need to run tests with mismatched client/server versions :-) (I'd also want to change the API quite a bit to make it easier to maintain like that)<br>
We'd still run into the issues I discovered while working on the proc_macro PR around unmangled symbols in std causing things like panics to not work properly when mixing std versions, though, and that might be a bit tricky.</p>



<a name="245456449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245456449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nika Layzell <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245456449">(Jul 09 2021 at 15:17)</a>:</h4>
<p>We'd also need to expand the proc_macro interface to support all of the features which built-in macros take advantage of (like the ability to expand nested macros into literals as <span class="user-mention" data-user-id="232018">@Daniel Henry-Mantilla</span> mentioned). Getting functionality like that into proc_macro might be nice anyway though :-)</p>



<a name="245456888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245456888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245456888">(Jul 09 2021 at 15:20)</a>:</h4>
<p>the mismatch only happens during bootstrapping</p>



<a name="245456939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245456939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245456939">(Jul 09 2021 at 15:21)</a>:</h4>
<p>i.e. <code>-Z build-std</code> shouldn't hit the old version</p>



<a name="245457169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245457169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245457169">(Jul 09 2021 at 15:22)</a>:</h4>
<p>and I wouldn't move all the macros right away, tbf</p>



<a name="245457874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245457874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245457874">(Jul 09 2021 at 15:27)</a>:</h4>
<p>If builtin macros are made proc-macros, I would prefer if they are still compiled into rustc itself. I would like to see the build scripts used during libstd builds to go away too.</p>



<a name="245458047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245458047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245458047">(Jul 09 2021 at 15:29)</a>:</h4>
<p>that's completely separate from what I'm suggesting, I guess. the unstable <code>proc_macro::quote!</code> macro (if we still have it) is implemented today as a proc macro, but compiled into <code>rustc</code> (rather than as its own dylib), and it would be easy to do the same for some builtin macros</p>



<a name="245458732"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245458732" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nika Layzell <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245458732">(Jul 09 2021 at 15:35)</a>:</h4>
<p>It does still exist: <a href="https://github.com/rust-lang/rust/blob/e916b7cb7708e470be8d0134bdf39479051a5c44/library/proc_macro/src/quote.rs#L64">https://github.com/rust-lang/rust/blob/e916b7cb7708e470be8d0134bdf39479051a5c44/library/proc_macro/src/quote.rs#L64</a></p>



<a name="245458850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/built-in%20macros%20vs%20proc%20macro/near/245458850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nika Layzell <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/built-in.20macros.20vs.20proc.20macro.html#245458850">(Jul 09 2021 at 15:36)</a>:</h4>
<p>It's implemented there using the <code>proc_macro</code> API, and exported as a builtin macro here: <a href="https://github.com/rust-lang/rust/blob/e916b7cb7708e470be8d0134bdf39479051a5c44/library/proc_macro/src/lib.rs#L273">https://github.com/rust-lang/rust/blob/e916b7cb7708e470be8d0134bdf39479051a5c44/library/proc_macro/src/lib.rs#L273</a> (<a href="https://searchfox.org/rust/rev/2daa26b7caad3742c9c61849c67d7341c3df5b97/compiler/rustc_builtin_macros/src/lib.rs#115">https://searchfox.org/rust/rev/2daa26b7caad3742c9c61849c67d7341c3df5b97/compiler/rustc_builtin_macros/src/lib.rs#115</a>)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>